from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

from datetime import datetime

import util
from datamodel import Student

class SearchHandler(webapp.RequestHandler):
  def get(self):
    util.ensure_login(self)
    #self.response.headers['Content-Type'] = 'text/html'
    grad_year = int(self.request.get('grad_year') or 2010)
    students = Student.all()
    students.filter("grad_date >=", datetime(grad_year, 1, 1))
    template_values = { 'grad_year': grad_year,
                        'students': students }
    util.render_template(self, 'search.tpl', template_values)

application = webapp.WSGIApplication(
                                     [('/search', SearchHandler)],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()

